﻿using System.Xml.XPath;
using System.Web;
using System.Security.Permissions;
using System.Xml;
using Com.FastSearch.SharePoint.Interfaces;

namespace Com.FastSearch.SharePoint.WebControls.ESPSearchWebParts.UI
{
    /// <summary>
    /// 
    /// </summary>
    public class ESPFeaturedContent : ESPSearchWebPart
    {
        #region Private variables

        /// <summary>
        /// <see cref="IXPathNavigable"/> (XmlDocument) containing the featured content as xml document which is used for the xslt transormation.
        /// </summary>
        private IXPathNavigable featuredContentXml = null;

        #endregion

        #region ESPSearchWebPart overrides

        /// <inheritdoc/>
        public override string GetEmbeddedXsl()
        {
            return LoadXslFromAssembly("FeaturedContent.xslt");
        }

        /// <inheritdoc/>
        protected override void ConfigureSearch()
        {
            // Nothing to do
        }

        /// <inheritdoc/>
        [AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        protected override XPathNavigator GetXPathNavigator(string viewPath)
        {
            if (featuredContentXml != null)
            {
                return featuredContentXml.CreateNavigator();
            }
            // Empty result list
            return new XmlDocument().CreateNavigator();
        }

        /// <inheritdoc/>
        public override void SetSearchResult(IESPSearchResult SearchResult)
        {

            if (SearchResult != null)
            {
                featuredContentXml = SearchResult.GetXmlFeaturedContent(Page.Request, ESPSearchGroupID, SearchRequest);
            }
        }

        #endregion

    }
}
